home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / syscall / Fs_Read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-21  |  2.5 KB  |  79 lines

  1. /* 
  2.  * Fs_Read.c --
  3.  *
  4.  *    Source code for the Fs_Read library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Fs_Read.c,v 1.2 88/06/21 11:14:50 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <sprite.h>
  21. #include <status.h>
  22. #include <fs.h>
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Fs_Read --
  29.  *
  30.  *      The "normal" Fs_Read routine for user code.  Read from the file
  31.  *      indicated by the stream id into the buffer.  bufSize indicates how
  32.  *      much data to read, and amountReadPtr is an output parameter that
  33.  *      indicates how much data were read.  A length of zero means
  34.  *      end-of-file.
  35.  *
  36.  *      If Fs_RawRead blocks to wait for data on the stream and a signal
  37.  *      is received by the process during the wait, then the system call
  38.  *      is aborted in order to process the signal.  When the signal has
  39.  *      been processed, the system call will return with a
  40.  *      GEN_ABORTED_BY_SIGNAL result, and *readCountPtr will have been
  41.  *      updated to reflect the number of bytes read so far.  This routine
  42.  *      will detect this condition and restart the system call to read the
  43.  *      remainder of the data.
  44.  *
  45.  * Results:
  46.  *    An error code.
  47.  *
  48.  * Side effects:
  49.  *    The read access pointer for the stream is advanced by
  50.  *    the amount of data read.
  51.  *
  52.  *----------------------------------------------------------------------
  53.  */
  54.  
  55. ReturnStatus
  56. Fs_Read(streamID, amountRead, buffer, amountReadPtr)
  57.     int        streamID;    /* The user's index into its open file list */
  58.     int        amountRead;    /* The amount of bytes to read */
  59.     Address    buffer;        /* The storage place for the read */
  60.     int        *amountReadPtr;    /* The amount of bytes actually read */
  61. {
  62.     int    realAmtRead;
  63.     ReturnStatus status;
  64.  
  65.     *amountReadPtr = 0;
  66.     do {
  67.     status = Fs_RawRead(streamID, amountRead, buffer, &realAmtRead);
  68.     *amountReadPtr += realAmtRead;
  69.     if (status == GEN_ABORTED_BY_SIGNAL) {
  70.         amountRead -= realAmtRead;
  71.         if (amountRead <= 0) {
  72.         return(SUCCESS);
  73.         }
  74.         buffer += realAmtRead;
  75.     }
  76.     } while (status == GEN_ABORTED_BY_SIGNAL);
  77.     return(status);
  78. }
  79.